package optional;

import optional.vo.A;
import optional.vo.B;
import optional.vo.C;

import java.util.Optional;

/**
 * 级联optional引用测试
 */
public class CascadeReferenceTest {

    public static void main(String[] args) {

        C c = new C();
        c.setName("tuyou");

        B b = new B();
        b.setC(Optional.of(c));

        A a = new A();
        a.setB(Optional.of(b));

        Optional<String> name = a.getB().flatMap(B::getC).map(item -> item.getName());
        System.out.println(name.orElse("获取不到名字"));
    }
}
